package com.salt.modules.sys.app;

import com.salt.common.json.AjaxJson;
import com.salt.core.oss.OssTemplate;
import com.salt.core.persistence.Page;
import com.salt.core.tool.utils.StringUtil;
import com.salt.core.web.BaseController;
import com.salt.modules.sys.entity.EditionFiles;
import com.salt.modules.sys.service.EditionFilesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * (EditionFiles)表控制层
 *
 * @author makejava
 */
@Api(tags = "手机端版本更新信息")
@RestController
@CrossOrigin
@RequestMapping("app/edition/files")
public class AppEditionFilesController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private EditionFilesService editionFilesService;
    @Resource
    private OssTemplate ossTemplate;


    /**
     * @param type 0 安卓 1 苹果
     * @return
     * @Author yan
     */
    @ApiOperation(value = "分页查询:根据前台参数分页查询")
    @GetMapping("detail")
    public AjaxJson list(@RequestParam Integer type) {
        EditionFiles editionFiles = new EditionFiles();
        editionFiles.setType(type);
        //查询第一页第一个
        int pageNo = 1;
        int pageSize = 1;

        Page<EditionFiles> page = editionFilesService.findPage(new Page<EditionFiles>(pageNo, pageSize), editionFiles);
        if (page.getList() != null && page.getList().size() > 0) {
            editionFiles = page.getList().get(0);
            if (StringUtil.isNotBlank(editionFiles.getNewFileName())) {
                editionFiles.setNewFileName(ossTemplate.outerFileLink(editionFiles.getNewFileName()));
            }
        }
        return AjaxJson.success().put("data", editionFiles);
    }

}